widget-factory: Make sure we close popover on page 3
authorMatthias Clasen <mclasen@redhat.com>
Tue, 3 Nov 2020 17:09:43 +0000 (12:09 -0500)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 3 Nov 2020 17:09:43 +0000 (12:09 -0500)
We don't want the popover to stay open when we open
an about dialog or shortcuts window. Since cascade-popdown
would also affect e.g. the context menu of the text widgets,
do this explicitly.

demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index e86ebf6ee4b2854c96d83364a07a2b3b0460595f..6d022bb2032b374e2965566a8dcf5fad9452ef1c 100644 (file)
@@ -260,6 +260,8 @@ activate_about (GSimpleAction *action,
                 gpointer       user_data)
 {
   GtkApplication *app = user_data;
+  GtkWindow *window;
+  GtkWidget *button;
   const char *authors[] = {
     "Andrea Cimitan",
     "Cosimo Cecchi",
@@ -277,6 +279,10 @@ activate_about (GSimpleAction *action,
 
   s = g_string_new ("");
 
+  window = gtk_application_get_active_window (app);
+  button = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "open_menubutton"));
+  gtk_menu_button_popdown (GTK_MENU_BUTTON (button));
+
   os_name = g_get_os_info (G_OS_INFO_KEY_NAME);
   os_version = g_get_os_info (G_OS_INFO_KEY_VERSION_ID);
   if (os_name && os_version)
@@ -326,6 +332,21 @@ activate_about (GSimpleAction *action,
   g_free (os_version);
 }
 
+static void
+activate_shortcuts_window (GSimpleAction *action,
+                           GVariant      *parameter,
+                           gpointer       user_data)
+{
+  GtkApplication *app = user_data;
+  GtkWindow *window;
+  GtkWidget *button;
+
+  window = gtk_application_get_active_window (app);
+  button = GTK_WIDGET (g_object_get_data (G_OBJECT (window), "open_menubutton"));
+  gtk_menu_button_popdown (GTK_MENU_BUTTON (button));
+  gtk_widget_activate_action (GTK_WIDGET (window), "win.show-help-overlay", NULL);
+}
+
 static void
 activate_quit (GSimpleAction *action,
                GVariant      *parameter,
@@ -2371,6 +2392,7 @@ main (int argc, char *argv[])
   GAction *action;
   static GActionEntry app_entries[] = {
     { "about", activate_about, NULL, NULL, NULL },
+    { "shortcuts", activate_shortcuts_window, NULL, NULL, NULL },
     { "quit", activate_quit, NULL, NULL, NULL },
     { "inspector", activate_inspector, NULL, NULL, NULL },
     { "main", NULL, "s", "'steak'", NULL },
index c4410a1ab2ee24deab5857170a5d5c94a9e0ac8c..3a7e2533fa98152e483c64f4965e32da88204f84 100644 (file)
@@ -51,7 +51,7 @@
       </item>
       <item>
         <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
-        <attribute name="action">win.show-help-overlay</attribute>
+        <attribute name="action">app.shortcuts</attribute>
       </item>
       <item>
         <attribute name="label" translatable="yes">_About Widget Factory</attribute>